package dianmobile.eistarandroid.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * this class manage setting info
 * Created by dianmobile_yy on 15/11/17.
 */
public class SettingInfoManager {

    private int timeInterval;
    private boolean isAutoShowPicture;
    private boolean isOnlyShowUnread;
    private int uploadPictureQuality;
    private boolean isAutoCheckUpdate;

    SharedPreferences sp;

    public SettingInfoManager(Context context) {

        sp = context.getSharedPreferences(ConstantsData.DB_PER, 0);
    }

    public int getTimeInterval() {
        timeInterval = sp.getInt(ConstantsData.K_INT_TIME_INTERVAL, 0);
        return timeInterval;
    }

    public void setTimeInterval(int timeInterval) {
        this.timeInterval = timeInterval;
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(ConstantsData.K_INT_TIME_INTERVAL, timeInterval);
        editor.commit();
    }

    public boolean isAutoShowPicture() {
        isAutoShowPicture = sp.getBoolean(ConstantsData.K_BOOL_AUTO_SHOW_PICTURE, true);
        return isAutoShowPicture;
    }

    public void setIsAutoShowPicture(boolean isAutoShowPicture) {
        this.isAutoShowPicture = isAutoShowPicture;
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(ConstantsData.K_BOOL_AUTO_SHOW_PICTURE, isAutoShowPicture);
        editor.commit();
    }

    public boolean isOnlyShowUnread() {
        isOnlyShowUnread = sp.getBoolean(ConstantsData.K_BOOL_ONLY_SHOW_UNREAD, false);
        return isOnlyShowUnread;
    }

    public void setIsOnlyShowUnread(boolean isOnlyShowUnread) {
        this.isOnlyShowUnread = isOnlyShowUnread;
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(ConstantsData.K_BOOL_ONLY_SHOW_UNREAD, isOnlyShowUnread);
        editor.commit();
    }

    public int getUploadPictureQuality() {
        uploadPictureQuality = sp.getInt(ConstantsData.K_INT_UPLOAD_PIC, 0);
        return uploadPictureQuality;
    }

    public void setUploadPictureQuality(int uploadPictureQuality) {
        this.uploadPictureQuality = uploadPictureQuality;
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(ConstantsData.K_INT_UPLOAD_PIC, uploadPictureQuality);
        editor.commit();
    }

    public boolean isAutoCheckUpdate() {
        isAutoCheckUpdate = sp.getBoolean(ConstantsData.K_BOOL_AUTO_UPDATE, true);
        return isAutoCheckUpdate;
    }

    public void setIsAutoCheckUpdate(boolean isAutoCheckUpdate) {
        this.isAutoCheckUpdate = isAutoCheckUpdate;
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(ConstantsData.K_BOOL_AUTO_UPDATE, isAutoCheckUpdate);
        editor.commit();
    }
}
